<!-- 小号转移弹窗 -->
<template>
  <el-dialog
    width="750px"
    :visible="visible"
    :lock-scroll="false"
    :destroy-on-close="true"
    custom-class="ele-dialog-form"
    title="小号转移"
    @update:visible="updateVisible"
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="82px">
          <el-form-item label="主账号:" prop="pid">
            <el-input
              clearable
              :maxlength="20"
              v-model="form.pid"
              placeholder="请输入主账号"
            />
          </el-form-item>
          <el-form-item label="备注:" prop="remark">
            <el-input
              clearable
              type="textarea"
              :row="5"
              v-model="form.remark"
              placeholder="请输入备注"
            />
          </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消 </el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "MemberEdit",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({ status: 1, gender: 1 }, this.data),
      // 表单验证规则
      rules: {
        pid: [
            { required: true, message: "请输入主账号", trigger: "blur" }
        ],
        remark: [
            { required: true, message: "请输入备注", trigger: "blur" }
        ],
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      // 会员等级列表
      memberLevelList: []
    };
  },
  watch: {
    data(){
      this.form=Object.assign({}, this.data);
    }
  },
  mounted() {
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          const saveform = {
            id: this.form.id,
            pid:this.form.pid,
            remark:this.form.remark,
          };
          this.$http
            .post("/Member/setMemberChild", saveform)
            .then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message({ type: "success", message: res.data.msg });
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit("done");
              } else {
                this.$message.error(res.data.msg);
              }
            })
            .catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit("update:visible", value);
    },
  }
};
</script>

<style scoped></style>
